package com.ninthgroup.benlailife.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.fastjson.JSONObject;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.ninthgroup.benlailife.R;
import com.ninthgroup.benlailife.bean.homepage.HomeEntity;
import com.ninthgroup.benlailife.config.UrlConstans;

import java.util.HashMap;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment {
    private RequestQueue queue;
    private String tag="HomeFragment";


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View v=inflater.inflate(R.layout.fragment_home, container, false);
        loadData();
        return v;
    }

    private void loadData() {

        queue = Volley.newRequestQueue(getActivity());
        StringRequest request=new StringRequest(Request.Method.POST, UrlConstans.POST_HOMEPAGE, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                HomeEntity entity= JSONObject.parseObject(response,HomeEntity.class);
                if (entity!=null&&entity.getError().equals("0")){

                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(tag,error.toString());
            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String>params=new HashMap<String, String>();
                params.put("systemVersion","4.3");
                params.put("lotType","2");
                params.put("phoneModel","R8007");
                params.put("deviceId","864182026522293a4:3d:78:0d:b6:fe");
                params.put("version","2.1.1");
                params.put("source","3");
                params.put("pageid","com.android.benlai.activity.MainActivity");
                params.put("localcity","216");
                params.put("sign","B7A0095FDC6A26543511DFF418D496CE");
                return params;
            }
        };
        request.setTag(tag);
        queue.add(request);
    }

    @Override
    public void onPause() {
        super.onPause();
        queue.cancelAll(tag);
    }
}
